import { ApiProperty } from '@nestjs/swagger';
import { Exclude, Type } from 'class-transformer';
import {
  IsNotEmpty,
  Length,
  IsString,
  IsOptional,
  IsEnum,
  IsNumber,
} from 'class-validator';
import { Role } from '../../roles/entities/role.entity';

// 创建学生dto
export class CreateStudentDto {
  @ApiProperty({ example: '1234567', description: '学号' })
  @IsString()
  @IsNotEmpty({ groups: ['create'], message: '学号必须填写' })
  studentNumber: string;

  @ApiProperty({ example: '张三', description: '姓名' })
  @IsString()
  @IsNotEmpty({ groups: ['create'], message: '姓名必须填写' })
  s_name: string;

  @ApiProperty({ example: '张三', description: '家庭地址' })
  @IsString()
  @IsNotEmpty({ groups: ['create'], message: '家庭地址必须填写' })
  s_address: string;

  // @ApiProperty({ example: '123456', description: '密码' })
  @IsOptional()
  // @IsString()
  // @IsNotEmpty({ groups: ['create'], message: '密码必须填写' })
  // @Length(6, 20, { groups: ['create'], message: '密码长度必须大于等于6位' })
  password: string;

  @ApiProperty({
    description: '性别',
    example: 1,
    required: false,
    enum: [0, 1, 2],
  })
  @IsOptional()
  @IsEnum(
    { 男: 0, 女: 1, 保密: 2 },
    {
      message: 'status只能传入数字0或1,2',
    },
  )
  @Type(() => Number)
  gender?: number;

  // @ApiProperty({ example: '1', description: 'id' })
  @IsOptional()
  id?: string;

  @ApiProperty({ example: 1, description: '学院id' })
  @IsNumber()
  @IsNotEmpty({ groups: ['create'], message: '请选择学院' })
  department_id: number;

  @ApiProperty({ example: 1, description: '专业id' })
  @IsNumber()
  @IsNotEmpty({ groups: ['create'], message: '请选择专业' })
  major_id: number;

  @ApiProperty({ example: '角色名', description: '角色名' })
  @IsNumber(
    {
      allowNaN: false,
      allowInfinity: false,
    },
    { each: true },
  )
  @IsOptional()
  roleIds: number[];

  roles: Role[];
}
